# 家具
class HouseItem:
    def __init__(self, name, area):
        """
        初始化家具
        :param name: 家具的名称
        :param area: 家具的占地面积
        """
        self.name = name
        self.area = area

    def __str__(self):
        return "%s 占地面积为%.2f" % (self.name, self.area)


bed = HouseItem('床', 4)
chest = HouseItem('衣柜', 2)
table = HouseItem('餐桌', 1.5)


# 房子
class House:
    def __init__(self, type, area, ):
        """
        房子初始化
        :param type: 户型
        :param area: 总面积
        """
        self.type = type
        self.area = area
        self.free_area = area
        self.item_list = []

    def __str__(self):
        return ("户型:%s\n总面积:%.2f[剩余:%.2f]\n家具:%s"
                % (self.type,self.area,self.free_area,self.item_list))

    def add_item(self,item):
        # print('要添加 %s' % item)
        if item.area > self.free_area:
            print('剩余面积不足!')
            return
        self.item_list.append(item.name)
        self.free_area -= item.area


my_home = House('两室一厅',60)
my_home.add_item(bed)
my_home.add_item(chest)
my_home.add_item(table)


print(my_home)

